package com.by.bean.params;

import com.by.common.utils.MapUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;


public class Page {

    @ApiModelProperty("当前第几页,默认第一页")
    int page;

    @ApiModelProperty(value = "每页记录数，默认10条",required = false)
    int pageSize;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        if (page == 0 )
            this.page = 1;
        else
            this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if (pageSize == 0)
            this.pageSize = 10;
        else
            this.pageSize = pageSize;
    }

    public Map toMap(){

        //先转换父类
        Map parentMap = MapUtils.convertToMap(this.getClass().getSuperclass(),this);

        //获取当前类
        Map childMap = MapUtils.convertToMap(this.getClass(),this);
        parentMap.putAll(childMap);
        return parentMap;
    }
}
